package com.zhiche.lisa.bms.controller.invoice;


import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.dao.model.invoice.InvoiceReg;
import com.zhiche.lisa.bms.service.invoice.InvoiceRegService;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 发票登记 前端控制器
 * </p>
 *
 * @author liuanshun
 * @since 2018-09-27
 */
@RestController
@RequestMapping("/invoiceReg")
public class InvoiceRegController {
    private static final Logger LOGGER = LoggerFactory.getLogger(InvoiceRegController.class);
    @Autowired
    private InvoiceRegService invoiceRegService;

    /**
     * 获取待付金额为空发票
     *
     * @return
     */
    @PostMapping(value = "/queryInvoiceRegOfNotLackSum")
    @ApiOperation(value = "获取待付金额为空发票", notes = "获取待付金额为空发票", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<Page<InvoiceReg>> queryInvoiceRegOfNotLackSum(@RequestBody Page<InvoiceReg> page) {
        LOGGER.info("InvoiceRegController.queryInvoiceRegOfNotLackSum param： {}");
        RestfulResponse<Page<InvoiceReg>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(invoiceRegService.queryInvoiceRegOfNotLackSum(page));
        } catch (BaseException e) {
            LOGGER.error("InvoiceRegController.queryInvoiceRegOfNotLackSum error:{}", e.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        } catch (Exception e) {
            LOGGER.error("InvoiceRegController.queryInvoiceRegOfNotLackSum error:{}", e.getMessage());
            result.setMessage("获取发票信息异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }
}

